package com.ls.common.aop.core;

import com.ls.base.utils.FieldUtil;
import org.springframework.core.annotation.AnnotationUtils;

import java.util.Arrays;

/**
 * @author: xiaosu
 * @date: 2018-09-20  21:44
 */
public interface KeywordGenerator {

    /**
     * 生成keyword的实现
     * @return
     */
    default public String keywordGenerator() {

        StringBuilder sb = new StringBuilder();

        Arrays.stream(this.getClass().getDeclaredFields()).forEach(item -> {

            if (AnnotationUtils.getAnnotation(item, KeywordField.class) != null) {
                Object value = FieldUtil.readField(this, item.getName());

                if (value != null) {
                    sb.append(value.toString());
                }
            }

        });

        return sb.toString();

        //return ReflectionToStringBuilder.toString(this, ToStringStyle.NO_FIELD_NAMES_STYLE);
    }
}
